package com.yanfan.web.controller.constant;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;

/**
 * 解析streamId各种状态
 */
@Getter
@AllArgsConstructor
public enum SanJiangYunCallBackType {
    ONLINE("online","设备在线状态"),   //在线离线
    HERAR_BEAT("heartbeat","设备心跳"),
    SELF_CHECK("self_check","设备自检"),
    FIRE_ALARM("fireAlarm","火警状态"),    //火警报警和消除
    INTEGRAL("integral", "拆除故障告警"),     //拆除或者完整
    BATTERY_POWER("batteryPower","电池电量"),
    SIGNAL_STRENGTH("signalStrength","信号强度"),
    RESET("reset","[复位]设备恢复"),
    IMEI("IMEI","上报IMEI"),
    ICCID("ICCID","上报ICCID"),
    COMMUNICATION("communication","上报通信故障"),
    SMOKESCOPE("smokeScope","上报烟雾浓度值"),
    POWER("power","低电压故障"),  //低电压告警或清除信号
    SENSOR("sensor","传感器故障"),   //故障或清除
    TEMP("temp","温度"),
    FIREALARM_TEMP("fireAlarm|temp","温感火警"),    //温感报警或清除
    SENSOR_TEMP("sensor|temp","温度传感器状态"),  //故障或故障解除

    HARDWARE("hardware","设备故障"),
    SELFCHECK("selfCheck","设备自检结束"),
    GAS("gas","可燃气体泄露报警"),

    //用户信息传输装置 JK-CS-01
    USER_00103003T01("00103003T01","【火警】1号主机2位3号"),
    USER_00103003T04("00103003T04","【请求】1号主机2位3号 启动"),
    USER_01381000T02("01381000T02","监测连接线路 通讯故障"),   //故障或恢复

    //电气火灾报警器 DH-9908N
    IMSI("IMSI","上报 IMSI"),
    SIGNAL_QUALITY("signalQuality","上报信号质量"),
    SIGNAL_LEVEL("signalLevel","上报信号等级"),
    TEMP_ALARM_3("tempAlarm|3","3路温度报警"),

    //燃气 JD-GAS  以上字段已存在

    //燃气 JD-GAS
    SHORT_CIRCUIT("shortCircuit","短路告警"),
    LEAK_AMPERE("leakAmpere","漏电流告警"),
    OVER_LOAD("overload","过载预警"),
    OVER_CURRENT("overCurrent","过流告警"),
    OVER_VOLTAGE("overVoltage","过压预警"),
    UNDER_VOLTAGE("underVoltage","欠压预警"),
    SURGE("surge","浪涌告警"),
    LEAK_AMPERE_SELF_CHECK("leakAmpereSelfCheck","漏电保护自检未完成告警"),
    STRIKE_SPARK("strikeSpark","打火告警"),
    AMPERE("ampere","电流"),
    AC_POWER("ACPower","掉电告警"),
    OPEN_BOX("openBox","开箱告警"),
    CONFIGURATION("configuration","组态告警"),
    OPEN_GATE("openGate","分闸预警"),
    CLOSE_GATE("closeGate","合闸预警"),
    VOLTAGE("voltage","电压"),

//MK系列
    POWER_TYPE("powerType","供电方式"),
    POWER_SOURCE("powerSource","电力来源"),
    REPORTINTERVAL("reportInterval","数据上报间隔"),
    LAST_TIME("lastTime","上一次上报时间"),
    DEVICE_NUMBER("deviceNumber","设备编号"),
    SIGNAL("signal","信号值"),
    TIME_INTERVAL("timeInterval","时间间隔"),
    CACHE_RECORD_COUNT("cacheRecordCount","缓存记录次数"),
    PRESSURE("pressure","液压"),
    WATER_LINE("waterLine","液位"),
    DIP_ANGLE("dipAngle","倾角"),
    SPEED("speed","风速"),
    VOLUME("volume","风量"),

    HIGH_THRESHOLD_PRESSURE("highThreshold|pressure","高阈值告警"), //告警或清除
    LOW_THRESHOLD_WATER_LINE("lowThreshold|waterLine","液位低阈值报警");  //液位低阈值报警或消除



    private String type;
    private String desc;
    /**
     * 根据type查找对应的枚举实例。
     *
     * @param type 要查找的类型字符串
     * @return 如果找到则返回对应的枚举实例，否则返回Optional.empty()
     */
    public static Optional<SanJiangYunCallBackType> findByType(String type) {
        return Arrays.stream(values())
                .filter(sanJiangYunCallBackType -> sanJiangYunCallBackType.getType().equals(type))
                .findFirst();
    }

    /**
     * 根据type查找对应的枚举实例，如果找不到则抛出IllegalArgumentException。
     *
     * @param type 要查找的类型字符串
     * @return 对应的枚举实例
     * @throws IllegalArgumentException 如果找不到对应的枚举实例
     */
    public static SanJiangYunCallBackType getRequiredByType(String type) {
        return findByType(type)
                .orElseThrow(() -> new IllegalArgumentException("未知的消息类型: " + type));
    }
}
